-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for empty list instead of null value. #630
Conversation
@@ -194,7 +194,8 @@ public override void WriteResponseHeaders(OutputFormatterWriteContext context) | |||
// Set the character set. | |||
MediaTypeHeaderValue currentContentType = GetContentType(response.Headers[HeaderNames.ContentType].FirstOrDefault()); | |||
RequestHeaders requestHeader = request.GetTypedHeaders(); | |||
if (requestHeader != null && requestHeader.AcceptCharset != null) | |||
// Starting from ASP .NET Core 3.0 AcceptCharset returns an empty collection instead of null. | |||
if (requestHeader?.AcceptCharset.Count > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (requestHeader?.AcceptCharset.Count > 0) | |
if (requestHeader?.AcceptCharset?.Count > 0) |
Let's be compatible with both versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIR this repo is for ASP .NET Core 3+. So it can't be ran with ASP .NET Core 2.x. This change make sense for OData/WebApi repo. Correct me if I'm wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also lean in favor of the AcceptCharset?.Count
check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the standard lib explicitly marks the properties that can be null as nullable in newer .NET versions e.g.: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.headers.requestheaders.cachecontrol?view=aspnetcore-6.0
I don't think that was the case for .NET Core 3.1 so it's hard to tell from just looking at the property whether it's safe to assume it can't be null.
@@ -194,7 +194,8 @@ public override void WriteResponseHeaders(OutputFormatterWriteContext context) | |||
// Set the character set. | |||
MediaTypeHeaderValue currentContentType = GetContentType(response.Headers[HeaderNames.ContentType].FirstOrDefault()); | |||
RequestHeaders requestHeader = request.GetTypedHeaders(); | |||
if (requestHeader != null && requestHeader.AcceptCharset != null) | |||
// Starting from ASP .NET Core 3.0 AcceptCharset returns an empty collection instead of null. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
Co-authored-by: John Gathogo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
No description provided.